package cn.ljy.uem.web.action.backstage.school;

import cn.ljy.authority.model.SysDepartment;
import cn.ljy.authority.model.query.SysDepartmentQuery;
import cn.ljy.authority.web.controller.backstage.BaseBackstageController;
import cn.ljy.common.model.result.ResponseData;
import cn.ljy.uem.model.SchoolDepartment;
import cn.ljy.uem.model.query.SchoolDepartmentQuery;
import cn.ljy.uem.service.SchoolDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 学校部门控制器
 *
 * @author 凡渊
 * @date 2022/07/18 10:28:52
 */
@Api(tags = "后台的部门模块")
@RestController
@RequestMapping(value = "/api/backstage/school/schooldepartment")
public class SchoolDepartmentController extends BaseBackstageController<SchoolDepartment, SchoolDepartmentQuery, Integer> {
    @Autowired
    private SchoolDepartmentService baseService;

    @ApiOperation(value = "查询所有部门")
    @GetMapping("/all")
    @Override
    protected ResponseData query(SchoolDepartmentQuery query) {
        return super.query(query);
    }

    @ApiOperation(value = "读取部门信息")
    @Override
    protected ResponseData get(@PathVariable("id") Integer id) {
        return super.get(id);
    }

    @ApiOperation(value = "分页查询部门列表")
    @Override
    protected ResponseData query(Integer page, Integer pageSize, SchoolDepartmentQuery query) {
        return super.query(page, pageSize, query);
    }

    @ApiOperation(value = "添加部门")
    @Override
    protected ResponseData add(@Valid @RequestBody SchoolDepartment SchoolDepartment) {
        return super.add(SchoolDepartment);
    }

    @ApiOperation(value = "批量删除指定的多个部门")
    @Override
    protected ResponseData deletes(@NotEmpty(message = "操作失败：请选择要移除的记录") Integer[] ids) {
        return super.deletes(ids);
    }

    @ApiOperation(value = "编辑部门")
    @Override
    protected ResponseData edit(@Valid @RequestBody SchoolDepartment SchoolDepartment) {
        return super.edit(SchoolDepartment);
    }


    @ApiOperation(value = "部门的树形列表")
    @GetMapping("/tree")
//    @PreAuthorize("hasAuthority('sys:department:query')")
    public ResponseData tree(SchoolDepartmentQuery schoolDepartmentQuery){
        List<SchoolDepartment> schoolDepartments = baseService.findTree(schoolDepartmentQuery);
        return ResponseData.success(schoolDepartments);
    }

}
